#ifndef DYNAMICARRAY_H
#define DYNAMICARRAY_H
/*
 *  DynamicArray.h
 *  Lec2Assignments
 *
 *  Created by Daniel Lin on 12/20/10.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */
#include <stdio.h>
#include <stdlib.h>

/*
 *	BEGIN_DECLARE_DYNAMIC_ARRAY
 */
#define BEGIN_DECLARE_DYNAMIC_ARRAY(T)										\
struct Dynamic_##T##Array {													\
	T*				_buf;													\
	T*				_bottom;												\
	T*				_top;													\
	unsigned int	_currentBufSize;										\
	unsigned int	_capacity;												\
																			\
	T	 (*popup)(struct Dynamic_##T##Array *);								\
	void (*push_back)(struct Dynamic_##T##Array *thisPointer, T* object);	\
	T	 (*objectAtIndex)(struct Dynamic_##T##Array *thisPointer,unsigned int index);


/*
 *	END_DECLARE_DYNAMIC_ARRAY
 */
#define END_DECLARE_DYNAMIC_ARRAY(T)										\
};																			\
typedef struct Dynamic_##T##Array Dynamic_##T##Array;
 
/*
 *	DECLARE_FUNCS
 */
#define DECLARE_FUNC_PUSHBACK(T) \
static void _PUSH_BACK_##T##_(Dynamic_##T##Array* thisPointer,T* object);

#define DECLARE_FUNC_POPUP(T) \
static T _POPUP_##T##_(Dynamic_##T##Array* thisPointer);

#define DECLARE_FUNC_OBJECTATINDEX(T) \
static T _OBJECT_##T##_ATINDEX(Dynamic_##T##Array* thisPointer,unsigned int index);

#define DECLARE_FUNC_INITARRAY(T) \
extern void _INIT_##T##ARRAY(Dynamic_##T##Array* thisPointer);

/*
 *	NEW_ARRAY
 */
#define DYNAMIC_ARRAY(T,NAME)	\
Dynamic_##T##Array NAME;		\
_INIT_##T##ARRAY(&NAME);


/**************************************************
 *	DYNAMIC_ARRAY(char)
 **************************************************/
BEGIN_DECLARE_DYNAMIC_ARRAY(char)
END_DECLARE_DYNAMIC_ARRAY(char)

DECLARE_FUNC_PUSHBACK(char)
DECLARE_FUNC_POPUP(char)
DECLARE_FUNC_INITARRAY(char)
DECLARE_FUNC_OBJECTATINDEX(char)


/**************************************************
 *	DYNAMIC_ARRAY(float)
 **************************************************/
BEGIN_DECLARE_DYNAMIC_ARRAY(float)
END_DECLARE_DYNAMIC_ARRAY(float)

DECLARE_FUNC_PUSHBACK(float)
DECLARE_FUNC_POPUP(float)
DECLARE_FUNC_INITARRAY(float)
DECLARE_FUNC_OBJECTATINDEX(float)

/**************************************************
 *	DYNAMIC_ARRAY(int)
 **************************************************/
BEGIN_DECLARE_DYNAMIC_ARRAY(int)
END_DECLARE_DYNAMIC_ARRAY(int)

DECLARE_FUNC_PUSHBACK(int)
DECLARE_FUNC_POPUP(int)
DECLARE_FUNC_INITARRAY(int)
DECLARE_FUNC_OBJECTATINDEX(int)


#endif